<?php

// module/Admin/src/Admin/Controller/AdminController.php:

namespace Admin\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Doctrine\ORM\EntityManager;
use Admin\Auth\Adapter;
use Admin\Form\Login;

class AdminController extends AbstractActionController {

    /**
     * @var Doctrine\ORM\EntityManager
     */
    protected $em;

    public function setEntityManager(EntityManager $em) {
        $this->em = $em;
    }

    public function getEntityManager() {
        if (null === $this->em) {
            $this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        }
        return $this->em;
    }

    public function indexAction() {
        $user = $this->getEntityManager()->getRepository('Admin\Entity\User')->findBy(array('login' => 'thomas'));
        return new ViewModel(array(
                    'user' => $user,
                ));
    }
    
    public function loginAction(){
        $loginForm = new Login();
        $loginForm->prepare();
        $login = $loginForm->get('name');
        
        echo '<'. $login->getAttribute('label');
        echo $login;
        $auth = new Adapter('thomas', 'toto');
        var_dump($auth->authenticate());exit;
    }

}

?>